package com.cn.hotel.servlet.back.rooms;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.RoomModel;
import com.cn.hotel.service.IRoomService;
import com.cn.hotel.service.impl.RoomServiceImpl;
import com.cn.hotel.util.Upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/room/roomEdit")
public class RoomEditServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        Upload.imgUpload(req);

        RoomModel roomModel = new RoomModel();
        roomModel.setRoomId(Integer.parseInt((String) req.getAttribute("roomId")));
        roomModel.setRoomType((String) req.getAttribute("roomType"));
        roomModel.setRoomPrice(Double.parseDouble((String) req.getAttribute("roomPrice")));
        roomModel.setRoomTitle((String) req.getAttribute("roomTitle"));
        roomModel.setRoomPhoto((String) req.getAttribute("roomPhoto"));
        roomModel.setRoomIntroduce((String) req.getAttribute("roomIntroduce"));
        IRoomService iRoomService = new RoomServiceImpl();
        int result = iRoomService.edit(roomModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
